﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace ebMS3dotnet.Core
{
    public class ebMS3Header : MessageHeader
    {
        private IebMS3HeaderWriter _writer;

        public ebMS3Header(IebMS3HeaderWriter writer)
        {
            _writer = writer;
        }
        protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
        {
            _writer.WriteHeader(writer);
        }

        protected override void OnWriteStartHeader(XmlDictionaryWriter writer, MessageVersion messageVersion)
        {

            writer.WriteStartElement("eb", Name, Namespace);
            if (messageVersion.Envelope == EnvelopeVersion.Soap11)
                writer.WriteAttributeString("mustUnderstand", Constants.SOAP11_NAMESPACE, "1");
            else
                writer.WriteAttributeString("mustUnderstand", Constants.SOAP12_NAMESPACE, "1");
        }

     
        public override string Name
        {
            get { return Constants.EBMS3_HEADERNAME; }
        }

        public override string Namespace
        {
            get { return Constants.EBMS3_NAMESPACE; }
        }

        public override bool MustUnderstand
        {
            get
            {
                return true;
            }
        }
    }    
}
